% The code is based on the following paper:
%   Chen, T. Y., Lin, Y. L., and Tzeng, L. Y., forthcoming.
%   Estimating probability weighting functions through option pricing bounds. Review of Asset Pricing Studies.
%
% Copyright: Tzu-Ying Chen, Yo-Lan Lin, Larry Y. Tzeng
% Date: January 30, 2024

clear

%% Setting                 
BV_Target = {'UB'};  

%% Optimal Risk Preferences under Rank-Dependent Expected Utility
FileName = ['Summary_AIO_OPT_AllPeriod_OP_UB'];
load(FileName, ...
     'Index_CR', 'Index_OPT', 'OPT_TAB');
clear FileName 

OPT = OPT_TAB(Index_CR, Index_OPT);                                 
clear Index_CR Index_OPT OPT_TAB

%% Plot Figure: Probability Weighting Function
x = 0:0.001:1;

h_PWF = figure;

plot(x, P1998(x, OPT(:, 1), OPT(:, 2)), ...
     'LineStyle', '-', ...
     'LineWidth', 2, ...
     'Color', 'r')
hold on

plot(x, x, ...
     'LineStyle', ':', ...
     'LineWidth', 2, ...
     'Color', 'k')
hold on
grid on

h = legend(['($\alpha^\ast$ , $\beta^\ast$) = (' num2str(OPT(:, 1)) ' , ' num2str(OPT(:, 2)) ')']);
set(h, 'FontSize', 15, ...
       'FontName', 'Times New Roman', ...
       'FontWeight', 'Bold', ...
       'Location', 'NorthWest', ...
       'Interpreter', 'Latex', ...
       'Box', 'Off')
clear h
   
h1 = xlabel('$p$');  
h2 = ylabel('$v(p)$');    
set([h1 h2], 'FontSize', 15, ...
             'FontName', 'Times New Roman', ...
             'FontWeight', 'Bold', ...
             'Interpreter', 'Latex')
clear h1 h2   
  
set(gca, 'XLim', [0 1], ...
         'XTick', 0:0.25:1, ...
         'FontSize', 15, ...
         'FontName', 'Times New Roman')
set(gca, 'YLim', [0 1], ...
         'YTick', 0:0.25:1, ...
         'FontSize', 15, ...
         'FontName', 'Times New Roman')    
    
set(gca, 'Layer', 'Top')

X = 29.7;                                                                  
Y = 21.0;                                                                  
XMargin = 1;                                                               
YMargin = 1;                                                               
XSize = X - 2 * XMargin;                                                   
YSize = Y - 2 * YMargin;                                                   
set(h_PWF, 'PaperUnits', 'Centimeters')
set(h_PWF, 'PaperSize', [X Y])
set(h_PWF, 'PaperPosition', [XMargin YMargin XSize YSize])
set(h_PWF, 'PaperOrientation', 'Portrait')
clear h_PWF X Y XMargin YMargin XSize YSize
clear x

%% Output
FileName = ['Figure_PWF_AIO_UB'];
saveas(gcf, [FileName '.eps'], 'epsc')
print(FileName, '-dpdf', '-fillpage')
winopen([FileName '.pdf'])
clear FileName